--#include "data\functions\Common\CommonFunc.lua" once				                    --一些通用方法
--#include "data\config\boss\PersonBossConfig.lua" once 			                    --个人副本
--#include "data\config\boss\StoneTombPigConfig.lua" once 			                    --石墓烧猪
--#include "data\config\item\ItemUseCountCfg.lua" once 			                        --道具次数
--#include "data\config\guild\guild.lua" once 			                                --行会
--#include "data\config\activityconfig\DailyActivity\PersonAnswerConfig.lua" once 		--个人答题
--#include "data\config\activityconfig\DailyActivity\WanShouMoPuConfig.lua" once 		--万兽魔谱
--#include "data\config\activityconfig\Escort\EscortConfig.lua" once 					--运镖活动
--#include "data\config\quest\EntrustReward.lua" once 									--伏魔任务
--#include "data\config\misc\MoneyTreeConfig.lua" once                                  --摇钱树

--部分需要通过（0,85）协议发送到客户端处理的操作类型
ActorDailyTimesOp = { 	enDailyOpTimes_FreeLocalRelive, enDailyOpTimes_DrawBossSoul, enDailyOpTimes_GuildAdventure, 
						enDailyOpTimes_GuildFightBoss, enDailyOpTimes_BloodFightPass, enDailyOpTimes_BloodFightFail,
					}

--[[
该套方法，目的是便于获取、控制某种操作的每日最大次数
包括：VIP特权、节日、活动等对于某操作的每日最大次数的加成
所有涉及到某日常操作最大次数的计算，都在以下方法内
]]
----------------------------------------每日操作次数-----------begin---------------------------------------------------
function ClearActorDailyDoneTimes( sysarg )
	local sVar = Actor.getStaticVar(sysarg)
	sVar.dailyDoneTimes 	= nil			--重置每日操作次数（部分）
	sVar.personBoss 		= nil			--重置个人BOSS进入次数
	sVar.dailyItemUseCount 	= nil			--重置每日使用道具次数
	sVar.teamFBEnterTimes	= nil			--重置团队副本进入次数
	sVar.vipBoss 			= nil			--重置VIP BOSS进入次数
	sVar.kongfuMaster 		= nil			--重置练功师进入次数
	sVar.concVipBoss 		= nil			--充值月卡boss
end

--[[检查某种操作，要进行opCount此，是否达到限制
没有限制或者已经进行的次数+要执行的次数<=最大次数，则返回true

/*某些操作的每日次数
仅CheckActorDailyDoneTimes()、GetActorDailyMaxTimes()、GetActorDailyDoneTimes()等方法使用
*/
enum enDailyOpTimes
{
	enDailyOpTimes_No				= 0,				//占位
	enDailyOpTimes_FreeLocalRelive	= 1,				//每日免费原地复活次数
	enDailyOpTimes_PersonBoss		= 2,				//每日参加个人副本次数
	enDailyOpTimes_StoneTomb		= 3,				//每日参加石墓烧猪副本次数
	enDailyOpTimes_UseItem			= 4,				//每日使用道具
	enDailyOpTimes_DrawBossSoul		= 5,				//每日抽取兽魂的次数
	enDailyOpTimes_MaterialFuben	= 6,				//材料副本
	enDailyOpTimes_Quest			= 7,				//任务
	enDailyOpTimes_MagicCity		= 8,				//迷幻魔城
	enDailyOpTimes_SpaceTrial		= 9,				//虚空试炼
	enDailyOpTimes_TeamFuben		= 10,				//团队副本
	enDailyOpTimes_ArenaBoss		= 11,				//每日参加擂台BOSS次数
	enDailyOpTimes_GuildAdventure	= 12,				//每日行会宝藏探险的次数
	enDailyOpTimes_GuildFightBoss	= 13,				//每日行会血战BOSS的次数（有进入次数，行会BOSS是开启后不限次数）
	enDailyOpTimes_PersonAnswer		= 14,				//每日个人答题次数
	enDailyOpTimes_BloodFightFail	= 15,				//每日血战到底失败次数
	enDailyOpTimes_BloodFightPass	= 16,				//每日血战到底闯关层数
	enDailyOpTimes_VipBoss			= 17,				//每日VIP BOSS参与次数
	enDailyOpTimes_KongFuMaster		= 18,				//进行练功师次数
	enDailyOpTimes_SceneAnswer		= 19,				//每日活动答题次数
	enDailyOpTimes_WorshipMonarch	= 20,				//膜拜君主
	enDailyOpTimes_TwelvePalace		= 21,				//十二星宫
	enDailyOpTimes_WanShouMoPu		= 22,				//万兽魔谱
	enDailyOpTimes_Escort			= 23,				//急速押镖、运镖活动
	enDailyOpTimes_BookQuest		= 24,				//天书任务、伏魔任务
	enDailyOpTimes_DreamBoss		= 25,				//幻境BOSS
	enDailyOpTimes_MoZun			= 26,				//魔尊战场、盟重杀神
	enDailyOpTimes_BaoZang			= 27,				//宝藏传说
	enDailyOpTimes_FireDragon		= 28,				//熔岩火龙
	enDailyOpTimes_SupplyContent	= 29,				//补给争夺
	enDailyOpTimes_ServerPK			= 30,  				//全服争霸
	enDailyOpTimes_DarkBox			= 31,				//暗之宝箱
	enDailyOpTimes_MoneyTree        = 32,               //摇钱树
	enDailyOpTimes_MoneyTree_BindYb = 33,               //摇钱树(绑元)
	enDailyOpTimes_ConcVipBoss		= 34,				//每日月卡Boss次数
	//以下是一个大操作拆分若干子操作(不使用)
	enDailyOpTimes_MaterialFuben_BloodRune  = 81,		//材料副本-血符
	enDailyOpTimes_MaterialFuben_Shield		= 82,		//材料副本-神盾
	enDailyOpTimes_MaterialFuben_Diamond	= 83,		//材料副本-宝石
	enDailyOpTimes_MaterialFuben_SealBead	= 84,		//材料副本-魂珠

	enDailyOpTimes_Max,
};
]]
function CheckActorDailyDoneTimes( sysarg, opType, opParam, opCount )
	local doCount = 1
	if opCount then
		doCount = opCount
	end
	local maxTimes 	= GetActorDailyMaxTimes( sysarg, opType, opParam )
	local doneTimes = GetActorDailyDoneTimes( sysarg, opType, opParam )

	--print("CheckActorDailyDoneTimes, maxTimes="..maxTimes..", doneTimes="..doneTimes..", doCount="..doCount)
	return maxTimes < 0 or doneTimes + doCount <= maxTimes
end

function AddActorDailyDoneTimes( sysarg, opType, opParam, addTimes )
	local doneTimes = GetActorDailyDoneTimes( sysarg, opType, opParam )
	SetActorDailyDoneTimes( sysarg, opType, opParam, doneTimes + addTimes )
end

--[[
获取玩家每日进行某操作的最大次数（包括各种加成）
返回值：-1：无限制，0-不允许，N-允许操作N次
]]
function GetActorDailyMaxTimes( sysarg, opType, opParam )
	--print("GetActorDailyMaxTimes, opType="..opType..", opParam="..opParam)
	if opType == enDailyOpTimes_FreeLocalRelive then			--每天免费复活的次数
		local maxTimes 	= GlobalConfig.dailyPlaceReliveTimes	--缺省N次
		local vipTimes  = GetVipGradePrivValue( sysarg, enVipPriv_LocalRelive ) or 0	
		maxTimes = maxTimes + vipTimes
		return maxTimes 			--缺省没有免费的复活次数
	elseif opType == enDailyOpTimes_BloodFightFail then		--每日血战到底失败次数
		local cfgTimes = BloodFightCfg.dailyFailTimesLimit or 0
		local maxTimes 	= cfgTimes
		return maxTimes
	elseif opType == enDailyOpTimes_BloodFightPass then		--每日血战到底闯关次数
		local cfgTimes = BloodFightCfg.dailyPassTimesLimit or 0
		local maxTimes 	= cfgTimes
		return maxTimes
	elseif opType == enDailyOpTimes_PersonAnswer then
		local cfgTimes = PersonAnswerConfig.enterTimesLimit or 0
		local maxTimes 	= cfgTimes
		return maxTimes
	elseif opType == enDailyOpTimes_TeamFuben then			--团队副本
		local fubenId = opParam
		local cfg = GetTeamFubenConfig( fubenId )
		local maxTimes 	= cfg.dailyTimesMax or 0
		return maxTimes
	elseif opType == enDailyOpTimes_ArenaBoss then
		local maxTimes = ArenaBossConfig.enterTimesLimit
		return maxTimes
	elseif opType == enDailyOpTimes_GuildAdventure then		--行会宝藏探险
		local cfgTimes = GuildConfig.guildAdventure.enterTimesLimit
		local maxTimes = cfgTimes
		return maxTimes
	elseif opType == enDailyOpTimes_GuildFightBoss then			--行会血战BOSS
		local guildId = Actor.getGuildId(sysarg)
		if guildId <= 0 then
			return 0
		end

		local guildLevel = GetGuildLevel(guildId)
		if guildLevel < 1 then
			return 0
		end
		local bossCfg = GuildConfig.guildBoss[guildLevel]
		if not bossCfg then
			return 0
		end
		local cfgTimes = #bossCfg.openConsume 		--配置有几次消费，就算几次次数
		local maxTimes = cfgTimes
		return maxTimes
	elseif opType == enDailyOpTimes_DrawBossSoul then		--每日抽取兽魂的次数
		local cfgTimes 		= NewBossSoulConfig.dailyDrawTimes
		local vipTimes 		= GetVipGradePrivValue( sysarg, enVipPriv_BossSoul, 0 ) or 0		    --每天VIP特权次数
		local concVipTimes 	= Actor.getConcurrentVipPriv( sysarg, enConcVipPriv_DrawBossSoul )		--特权抽取兽魂
		local maxTimes = cfgTimes + vipTimes + concVipTimes
		--print("GetActorDailyMaxTimes, cfgTimes="..cfgTimes..", concVipTimes="..concVipTimes..", maxTimes="..maxTimes)
		return maxTimes
	elseif opType == enDailyOpTimes_StoneTomb then
		if not StoneTombPigConfig.enterTimesLimit or StoneTombPigConfig.enterTimesLimit <= 0 then
			return -1 				--没有配置或0，表示不限制次数
		end
		local maxTimes = StoneTombPigConfig.enterTimesLimit
		return maxTimes
	elseif opType == enDailyOpTimes_PersonBoss then
		local bossIdx = opParam
		local bossCfg = PersonBossConfig[bossIdx]
		local maxTimes = 0
		if bossCfg then
			maxTimes = maxTimes + bossCfg.enterTimesLimit
		end
		return maxTimes
	elseif opType == enDailyOpTimes_VipBoss then			--VIP BOSS参与次数
		local vipLevel 	= opParam
		--print("GetActorDailyMaxTimes, vipLevel="..vipLevel)
		local vipCfg 	= GetVipGradeCfgByVipLevel( vipLevel )
		local cfgTimes 	= 0
		if vipCfg and vipCfg.boss then
			--print("GetActorDailyMaxTimes, xxx")
			cfgTimes = vipCfg.boss.enterTimesLimit
		end
		maxTimes = cfgTimes
		return maxTimes
	elseif opType == enDailyOpTimes_ConcVipBoss then
		local vipType 	= opParam
		local vipCfg 	= VipConcCfg.Vips[vipType]
		local cfgTimes 	= 0
		if vipCfg and vipCfg.boss then
			cfgTimes = vipCfg.boss.enterTimesLimit
		end
		maxTimes = cfgTimes
		return maxTimes
	elseif opType == enDailyOpTimes_KongFuMaster then
		local masterIdx = opParam
		local masterCgf = KongFuMasterConfig[masterIdx]
		local cfgTimes = 0
		if masterCgf then
			cfgTimes = masterCgf.enterTimesLimit
		end
		maxTimes = cfgTimes
		return maxTimes
	elseif opType == enDailyOpTimes_MaterialFuben then
		local fubenIdx = opParam
		local fubenCfg = MaterialFubenCfg[fubenIdx]
		local maxTimes = 0
		if fubenCfg then
			maxTimes = maxTimes + fubenCfg.dailyEnterTimes
		end
		return maxTimes
	elseif opType == enDailyOpTimes_UseItem then
		local itemId = opParam
		local maxTimes = 0
		local useCfg = ItemUseCountCfg[itemId]
		if useCfg then
			if useCfg.dailyUseLimit <= 0 then
				return -1 			--配置次数<=0，则表示不限制使用次数
			end
			maxTimes = useCfg.dailyUseLimit 
			local vipTimes = GetVipGradePrivValue( sysarg, enVipPriv_UseItem, itemId ) or 0		--每天VIP特权次数
			maxTimes = maxTimes + vipTimes
			--print("GetActorDailyMaxTimes, vipTimes="..vipTimes..", maxTimes="..maxTimes)
			return maxTimes
		end
		return -1 			--缺省不限制使用次数
	elseif opType == enDailyOpTimes_Quest then			--任务
		local questId = opParam
		local maxTimes = Actor.getQuestMaxTimes( sysarg, questId )
		return maxTimes
	elseif opType == enDailyOpTimes_MagicCity then		--魔域迷城
		local cityIdx = opParam
		local cityCfg = GetMagicCityCfgByCityIdx( cityIdx )
		if not cityCfg then
			return
		end
		local buyTimes = GetMagicCityMyValue( sysarg, cityIdx, MAGICCITY_MY_BUY_TIMES )
		local maxTimes = cityCfg.dailyEnterTimes + buyTimes
		return maxTimes
	elseif opType == enDailyOpTimes_SpaceTrial then		--血域试炼
		local maxTimes = SpaceTrialCfg.enterTimesLimit
		return maxTimes
	elseif opType == enDailyOpTimes_SceneAnswer then	--参与场景答题
		local maxTimes = 1
		return maxTimes
	elseif opType == enDailyOpTimes_WorshipMonarch then		--膜拜城主(1天2次)
		local maxTimes = 2
		return maxTimes
	elseif opType == enDailyOpTimes_TwelvePalace then		--十二星宫(1天1次)
		local maxTimes = 1
		return maxTimes
	elseif opType == enDailyOpTimes_WanShouMoPu then		--万兽魔谱(1天10次)
		local maxTimes = #WanShouMoPuConfig
		return maxTimes
	elseif opType == enDailyOpTimes_Escort then				--急速押镖、运镖活动
		local maxTimes = EscortConfig.Times
		return maxTimes
	elseif opType == enDailyOpTimes_BookQuest then			--天书任务、伏魔任务
		local maxTimes = 0
		maxTimes = maxTimes + GetActorDailyMaxTimes( sysarg, enDailyOpTimes_Quest, BookQuestConfig.BookQuestId )
		return maxTimes
	elseif opType == enDailyOpTimes_DreamBoss then			--幻境BOSS（每天1次，场景活动要1次）
		local maxTimes = 1
		return maxTimes
	elseif opType == enDailyOpTimes_MoZun then			--魔尊战场、盟重杀神（每天1次，场景活动要1次）
		local maxTimes = 1
		return maxTimes
	elseif opType == enDailyOpTimes_SupplyContent then	--补给争夺（每天1次，场景活动要1次）
		local maxTimes = 1
		return maxTimes	
	elseif opType == enDailyOpTimes_MoneyTree or opType == enDailyOpTimes_MoneyTree_BindYb then --摇钱树
		local maxTimes = 0
		local elem = DailyTypeToTreeCfg[opType]
		if elem and IsOpenServerDayInRange(elem.openServerDay) then
			maxTimes = elem.operateTimesCfg.maxTimes
		end
		local vipTimes 	= GetVipGradePrivValue( sysarg, enVipPriv_MoneyTree, 0 ) or 0		    --每天VIP特权次数
		maxTimes = maxTimes + vipTimes
		print("checkme time = "..maxTimes)
		return maxTimes
	end
	return 0
end

--[[
获取玩家当日已经进行某操作的次数
]]
function GetActorDailyDoneTimes( sysarg, opType, opParam )
	local sVar = Actor.getStaticVar(sysarg)
	if opType == enDailyOpTimes_FreeLocalRelive or opType == enDailyOpTimes_StoneTomb or opType == enDailyOpTimes_GuildFightBoss or
	   opType == enDailyOpTimes_DrawBossSoul or opType == enDailyOpTimes_ArenaBoss or opType == enDailyOpTimes_GuildAdventure or
	   opType == enDailyOpTimes_PersonAnswer or opType == enDailyOpTimes_BloodFightFail or opType == enDailyOpTimes_BloodFightPass or 
	   opType == enDailyOpTimes_SceneAnswer or opType == enDailyOpTimes_WorshipMonarch or opType == enDailyOpTimes_TwelvePalace or 
	   opType == enDailyOpTimes_DreamBoss or opType == enDailyOpTimes_MoZun or opType == enDailyOpTimes_SupplyContent or 
	   opType == enDailyOpTimes_MoneyTree or opType == enDailyOpTimes_MoneyTree_BindYb then
		if not sVar.dailyDoneTimes then
			sVar.dailyDoneTimes = {}
		end
		return sVar.dailyDoneTimes[opType] or 0
	elseif opType == enDailyOpTimes_TeamFuben then
		local fubenId = opParam
		if not sVar.teamFBEnterTimes then
			sVar.teamFBEnterTimes = {}
		end
		return sVar.teamFBEnterTimes[fubenId] or 0
	elseif opType == enDailyOpTimes_PersonBoss then			--个人副本
		if not sVar.personBoss then
			sVar.personBoss = {}
		end
		local bossIdx = opParam
		return sVar.personBoss[bossIdx] or 0
	elseif opType == enDailyOpTimes_VipBoss then			--VIP BOSS参与次数
		local vipLevel = opParam
		local sVar = Actor.getStaticVar(sysarg)
		if not sVar.vipBoss then
			sVar.vipBoss = {}
		end
		return sVar.vipBoss[vipLevel] or 0
	elseif opType == enDailyOpTimes_ConcVipBoss then
		local vipType = opParam
		local sVar = Actor.getStaticVar(sysarg)
		if not sVar.concVipBoss then
			sVar.concVipBoss = {}
		end
		return sVar.concVipBoss[vipType] or 0
	elseif opType == enDailyOpTimes_KongFuMaster then		--练功师
		local masterIdx = opParam
		local sVar = Actor.getStaticVar(sysarg)
		if not sVar.kongfuMaster then
			sVar.kongfuMaster = {}
		end
		return sVar.kongfuMaster[masterIdx] or 0
	elseif opType == enDailyOpTimes_MaterialFuben then		--材料副本
		local fubenIdx = opParam
		if not sVar.days then
			sVar.days = {}
		end
		if not sVar.days.materialFB then
			sVar.days.materialFB = {}
		end
		return sVar.days.materialFB[fubenIdx] or 0
	elseif opType == enDailyOpTimes_UseItem then
		local itemId = opParam
		local useCfg = ItemUseCountCfg[itemId]
		if useCfg then
			if not sVar.dailyItemUseCount then
				sVar.dailyItemUseCount = {}
			end
			local itemGroupId = opParam
			return sVar.dailyItemUseCount[useCfg.group] or 0
		end
		return 0
	elseif opType == enDailyOpTimes_Quest then			--任务
		local questId = opParam
		local doneTimes = Actor.getQuestDoneTimes( sysarg, questId )
		return doneTimes
	elseif opType == enDailyOpTimes_MagicCity then		--魔域迷城
		local cityIdx = opParam
		local cityCfg = GetMagicCityCfgByCityIdx( cityIdx )
		if not cityCfg then
			return
		end
		local doneTimes = GetMagicCityMyValue( sysarg, cityIdx, MAGICCITY_MY_DONE_TIMES )
		return doneTimes
	elseif opType == enDailyOpTimes_SpaceTrial then		--血域试炼
		local doneTimes = GetSpaceTrialMyValue( sysarg, SPACETRIAL_MY_DONE_TIMES )
		return doneTimes
	elseif opType == enDailyOpTimes_WanShouMoPu  then	--万兽魔谱
		local sVar = Actor.getStaticVar(sysarg)
		if not sVar.days then
			sVar.days = {}
		end
		local wsmpIndex = sVar.days.wsmpIndex or 1
		local doneTimes = wsmpIndex - 1
		if doneTimes < 0 then
			doneTimes = 0
		end
		return doneTimes
	elseif opType == enDailyOpTimes_Escort then				--急速押镖、运镖活动
		local sVar = Actor.getStaticVar(sysarg)
		local doneTimes = sVar.EscortTimes or 0
		return doneTimes
	elseif opType == enDailyOpTimes_BookQuest then			--天书任务、伏魔任务
		local doneTimes = 0
		doneTimes = doneTimes + GetActorDailyDoneTimes( sysarg, enDailyOpTimes_Quest, BookQuestConfig.BookQuestId )
		return doneTimes
	end
end

--[[
设置玩家当日已经进行某操作的次数
]]
function SetActorDailyDoneTimes( sysarg, opType, opParam, newTimes )
	local sVar = Actor.getStaticVar(sysarg)
	if opType == enDailyOpTimes_FreeLocalRelive or opType == enDailyOpTimes_StoneTomb or opType == enDailyOpTimes_GuildFightBoss or
	   opType == enDailyOpTimes_DrawBossSoul or opType == enDailyOpTimes_ArenaBoss or opType == enDailyOpTimes_GuildAdventure or 
	   opType == enDailyOpTimes_PersonAnswer or opType == enDailyOpTimes_BloodFightFail or opType == enDailyOpTimes_BloodFightPass or 
	   opType == enDailyOpTimes_SceneAnswer or opType == enDailyOpTimes_WorshipMonarch or opType == enDailyOpTimes_TwelvePalace or 
	   opType == enDailyOpTimes_DreamBoss or opType == enDailyOpTimes_MoZun or opType == enDailyOpTimes_SupplyContent or 
	   opType == enDailyOpTimes_MoneyTree or opType == enDailyOpTimes_MoneyTree_BindYb then
		if not sVar.dailyDoneTimes then
			sVar.dailyDoneTimes = {}
		end
		sVar.dailyDoneTimes[opType] = newTimes
	elseif opType == enDailyOpTimes_TeamFuben then
		local fubenId = opParam
		if not sVar.teamFBEnterTimes then
			sVar.teamFBEnterTimes = {}
		end
		sVar.teamFBEnterTimes[fubenId] = newTimes
	elseif opType == enDailyOpTimes_PersonBoss then
		if not sVar.personBoss then
			sVar.personBoss = {}
		end
		local bossIdx = opParam
		sVar.personBoss[bossIdx] = newTimes
	elseif opType == enDailyOpTimes_UseItem then
		local itemId = opParam
		local useCfg = ItemUseCountCfg[itemId]
		if useCfg then 	--有配置，才会记录使用次数
			if not sVar.dailyItemUseCount then
				sVar.dailyItemUseCount = {}
			end
			sVar.dailyItemUseCount[useCfg.group] = newTimes
		end
	elseif opType == enDailyOpTimes_VipBoss then			--VIP BOSS参与次数
		local vipLevel = opParam
		local sVar = Actor.getStaticVar(sysarg)
		if not sVar.vipBoss then
			sVar.vipBoss = {}
		end
		sVar.vipBoss[vipLevel] = newTimes
	elseif opType == enDailyOpTimes_ConcVipBoss then		--月卡 BOSS参与次数
		local vipType = opParam
		local sVar = Actor.getStaticVar(sysarg)
		if not sVar.concVipBoss then
			sVar.concVipBoss = {}
		end
		sVar.concVipBoss[vipType] = newTimes
	elseif opType == enDailyOpTimes_KongFuMaster then		--练功师
		local masterIdx = opParam
		local sVar = Actor.getStaticVar(sysarg)
		if not sVar.kongfuMaster then
			sVar.kongfuMaster = {}
		end
		sVar.kongfuMaster[masterIdx] = newTimes
	elseif opType == enDailyOpTimes_MagicCity then		--魔域迷城
		local cityIdx = opParam
		local cityCfg = GetMagicCityCfgByCityIdx( cityIdx )
		if not cityCfg then
			return
		end
		--print("SetActorDailyDoneTimes, ", newTimes="..newTimes)
		SetMagicCityMyValue( sysarg, cityIdx, MAGICCITY_MY_DONE_TIMES, newTimes )
	elseif opType == enDailyOpTimes_SpaceTrial then		--血域试炼
		SetSpaceTrialMyValue( sysarg, SPACETRIAL_MY_DONE_TIMES, newTimes  )
	elseif opType == enDailyOpTimes_WanShouMoPu then	--万兽魔谱（这里没有使用到）
		local sVar = Actor.getStaticVar(sysarg)
		if not sVar.days then
			sVar.days = {}
		end
		sVar.days.wsmpIndex = newTimes
	elseif opType == enDailyOpTimes_Escort then				--急速押镖、运镖活动（这里没有使用到）
		local sVar = Actor.getStaticVar(sysarg)
		sVar.EscortTimes = newTimes
	elseif opType == enDailyOpTimes_BookQuest then			--天书任务、伏魔任务（这里没有使用到，走任务系统）
		--空
	end
	SendActorDailyDoneTimes( sysarg, opType, opParam  )
end

function SendActorDailyDoneTimes( sysarg, opType, opParam  )
	--print("SendActorDailyDoneTimes, opType="..opType..", opParam")
	if opType == enDailyOpTimes_UseItem then
		local itemId = opParam
		SendItemTimesUsed(sysarg, itemId)
	else
		SendActorDailyOpTimesUsed( sysarg, opType, opParam )
	end
end

--[[下发玩家每日操作的最大次数和剩余次数（部分操作）
协议(0,85)
ActorDailyTimesOp有的才发
]]
function SendActorDailyOpTimesUsed( sysarg, opType, opParam )
	--print("SendActorDailyOpTimesUsed, opType="..opType..", opParam="..opParam)
	if not IsElemInList( ActorDailyTimesOp, opType ) then
		return
	end
	local netPack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sSendActorDailyOperationTimes)
	--local netPack = DataPack.allocPacket(sysarg, 0, 85)
	if netPack then
		local maxTimes 	= GetActorDailyMaxTimes( sysarg, opType, opParam )
		local doneTimes = GetActorDailyDoneTimes( sysarg, opType, opParam )
		local lastTimes	= maxTimes - doneTimes
		if lastTimes < 0 then
			lastTimes = 0
		end
		DataPack.writeShort(netPack, opType)
		DataPack.writeShort(netPack, maxTimes)
		DataPack.writeShort(netPack, lastTimes)
		DataPack.flush(netPack)
		--print("--->SendActorDailyOpTimesUsed, opType="..opType..", opParam="..opParam..", maxTimes="..maxTimes..", lastTimes="..lastTimes)
	end
end

function SendActorAllDailyOpTimes( sysarg )
	--local actorId = Actor.getActorId( sysarg )
	--print("SendActorAllDailyOpTimes, actorId="..actorId)
	for i, opType in ipairs( ActorDailyTimesOp ) do 			--发送操作剩余次数
		SendActorDailyOpTimesUsed( sysarg, opType, 0 )
	end

	SendAllItemsTimesUsed(sysarg)								--发送道具使用的剩余次数
end

--部分类型需要转换一下
function GetNewOpTypeByTypeAndParam( opType, opParam )
	if not opParam then
		return opType
	end

	local newOpType = nil
	if opType == enDailyOpTimes_MaterialFuben then
		if opParam == 1 then
			newOpType = enDailyOpTimes_MaterialFuben_BloodRune			--血符
		elseif opParam == 2 then
			newOpType = enDailyOpTimes_MaterialFuben_Shield				--神盾
		elseif opParam == 3 then
			newOpType = enDailyOpTimes_MaterialFuben_Diamond			--宝石
		elseif opParam == 4 then
			newOpType = enDailyOpTimes_MaterialFuben_SealBead			--魂珠
		end
	end
	--print("GetNewOpTypeByTypeAndParam, opType="..opType..", newOpType="..newOpType)
	return newOpType
end

--[[
获取未进行的次数
]]
function GetActorDailyUndoTimes( sysarg, opType, opParam )
	local maxTimes 	= GetActorDailyMaxTimes( sysarg, opType, opParam )
	local doneTimes = GetActorDailyDoneTimes( sysarg, opType, opParam )
	if doneTimes <= maxTimes then
		return maxTimes - doneTimes
	end
	return 0
end

function ShowActorDailyOpTimes( sysarg, opType, opParam )
	local maxTimes 	= GetActorDailyMaxTimes( sysarg, opType, opParam )
	local doneTimes = GetActorDailyDoneTimes( sysarg, opType, opParam )
	print("ShowActorDailyOpTimes, opType="..opType..", maxTimes="..maxTimes..", doneTimes="..doneTimes)
end

----------------------------------------每日操作次数-----------end---------------------------------------------------

----------------------------------------前几日操作次数----------begin-------------------------------------------------
function InitDailyDoneTimesBefore( sysarg )
	local sVar = Actor.getStaticVar(sysarg)
	if not sVar.doneTimesBefore then
		sVar.doneTimesBefore = {}
	end

	if not sVar.doneTimesBefore[1] then
		sVar.doneTimesBefore[1] = {}
	end

	if not sVar.doneTimesBefore[2] then
		sVar.doneTimesBefore[2] = {}
	end

	if not sVar.doneTimesBefore[3] then
		sVar.doneTimesBefore[3] = {}
	end
end

--[[
记录前一天已经完成某操作的次数
opType：每个操作唯一
]]
function GetDailyDoneTimesBefore( sysarg, daysBefore, newOpType )
	--print("GetActorDailyDoneTimesBefore, daysBefore="..daysBefore..", newOpType="..newOpType)
	InitDailyDoneTimesBefore( sysarg )
	local sVar = Actor.getStaticVar(sysarg)
	if not sVar.doneTimesBefore[daysBefore] then
		return 0
	end

	return sVar.doneTimesBefore[daysBefore][newOpType] or 0
end

function ClearDailyDoneTimesBefore( sysarg )
	local sVar = Actor.getStaticVar(sysarg)
	sVar.doneTimesBefore = nil
end

--[[
newOpType：任何一种活动、副本的newOpType都唯一
]]
function SetDailyDoneTimesBefore( sysarg, daysBefore, newOpType, value )
	--print("SetActorDailyDoneTimesBefore, opType="..opType..", opParam")
	InitDailyDoneTimesBefore( sysarg )
	local sVar = Actor.getStaticVar(sysarg)
	if not sVar.doneTimesBefore[daysBefore] then
		return 0
	end

	sVar.doneTimesBefore[daysBefore][newOpType] = value
end

--[[
记录X天前的玩家操作次数
]]
function RecordDailyDoneTimesBefore( sysarg, daysBefore )
	--print("RecordDailyDoneTimesBefore, daysBefore="..daysBefore)
	InitDailyDoneTimesBefore( sysarg )
	RecordDailyDoneTimesBeforeByType( sysarg, daysBefore, enDailyOpTimes_StoneTomb, nil )		--石墓烧猪次数
end

function RecordDailyDoneTimes( sysarg, opType, opParam )
	RecordDailyDoneTimesBeforeByType( sysarg, 3, opType, opParam )			--2天前->3天前
	RecordDailyDoneTimesBeforeByType( sysarg, 2, opType, opParam )			--1天前->1天前
	RecordDailyDoneTimesBeforeByType( sysarg, 1, opType, opParam )			--当天->1天前
end

--[[
记录N天前的玩家操作次数
]]
function RecordDailyDoneTimesBeforeByType( sysarg, daysBefore, opType, opParam )
	--print("RecordDailyDoneTimesBefore, daysBefore="..daysBefore..", opType="..opType)
	--InitDailyDoneTimesBefore( sysarg )
	local doneTimes = 0
	local newOpType = GetNewOpTypeByTypeAndParam( opType, opParam )
	if daysBefore <= 1 then
		doneTimes = GetActorDailyDoneTimes( sysarg, opType, opParam )		--取当天
	else
		doneTimes = GetDailyDoneTimesBefore( sysarg, daysBefore-1, newOpType )	--取上1天
	end
	--print("RecordDailyDoneTimesBefore, newOpType="..newOpType..", daysBefore="..daysBefore..", doneTimes="..doneTimes)
	SetDailyDoneTimesBefore( sysarg, daysBefore, newOpType, doneTimes )
end

--[[
获取过去三天内某操作的次数
]]
function GetDoneTimesBeforeByType( sysarg, newOpType )
	local doneTimes1 = GetDailyDoneTimesBefore( sysarg, 1, newOpType ) 		--前1天
	local doneTimes2 = GetDailyDoneTimesBefore( sysarg, 2, newOpType )		--前2天
	local doneTimes3 = GetDailyDoneTimesBefore( sysarg, 3, newOpType )		--前3天
	return doneTimes1 + doneTimes2 + doneTimes3
end


--[[
获取过去3天内某操作的未完成的次数
从创建角色算起
]]
function GetUndoTimesBeforeByType( sysarg, opType, opParam )
	local newOpType = GetNewOpTypeByTypeAndParam( opType, opParam )
	local doneTimes = GetDoneTimesBeforeByType( sysarg, newOpType, opParam )   		--过去3天已经进行的次数

	--抵扣根据创建角色的天数
	local creatDays = Actor.getDaysSinceCreateRole( sysarg ) 		--角色创建天数(1就是角色创建当天)
	local maxDays 	= creatDays - 1
	if maxDays < 0 then
		maxDays = 0
	elseif maxDays > 3 then
		maxDays = 3
	end
	local maxTimes  = GetActorDailyMaxTimes( sysarg, opType, opParam ) * maxDays			--可完成总次数
	--[[
	print("GetUndoTimesBeforeByType, creatDays="..creatDays..", maxDays="..maxDays)

	if opParam then
		print("GetUndoTimesBeforeByType, opType="..opType..", opParam="..opParam..", doneTimes="..doneTimes..", maxTimes="..maxTimes)
	else
		print("GetUndoTimesBeforeByType, opType="..opType..", doneTimes="..doneTimes..", maxTimes="..maxTimes)
	end
	]]


	if maxTimes > doneTimes then
		return maxTimes-doneTimes
	end
	return 0
end

function GetUndoTimesBeforeByDayAndType( sysarg, daysBefore, opType, opParam )
	local newOpType = GetNewOpTypeByTypeAndParam( opType, opParam )
	local doneTimes = GetDailyDoneTimesBefore( sysarg, daysBefore, newOpType ) 				--N天前
	local maxTimes  = GetActorDailyMaxTimes( sysarg, opType, opParam ) 			            --当天可完成总次数
	if maxTimes > doneTimes then
		return maxTimes-doneTimes
	end
	return 0
end


function ShowDailyDoneTimesBefore( sysarg, newOpType )
	--print("ShowDailyDoneTimesBefore, newOpType="..newOpType)
	InitDailyDoneTimesBefore( sysarg )
	local doneTimes1 = GetDailyDoneTimesBefore( sysarg, 1, newOpType ) 		--前1天
	local doneTimes2 = GetDailyDoneTimesBefore( sysarg, 2, newOpType )		--前2天
	local doneTimes3 = GetDailyDoneTimesBefore( sysarg, 3, newOpType )		--前3天
	print("ShowDailyDoneTimesBefore, doneTimes1="..doneTimes1..", doneTimes2="..doneTimes2..", doneTimes3="..doneTimes3)
end
----------------------------------------前几日操作次数----------end-------------------------------------------------

